// More on defining blocks:
// https://developers.google.com/blockly/guides/create-custom-blocks/define-blocks
import * as Blockly from 'blockly/core'

// 1------------代码块 输入代码
const code_input_json = {
  'type': 'code_input',
  'message0': ' 输入代码 %1',
  'args0': [
    {
      'type': 'field_input',
      'name': 'CODE',
      'text': ''
    }
  ],
  previousStatement: null, // 上连接
  nextStatement: null, // 下连接
  // inputsInline: 'code_input',
  colour: 290,
  tooltip: '',
  helpUrl: ''
}

// 创建积木
Blockly.Blocks['code_input'] = {
  init: function () {
    this.jsonInit(code_input_json)
  }
}

Blockly.JavaScript['code_input'] = function (block) {
  const code = block.getFieldValue('CODE')
  return `${code}\n`
}

// 2---------参数的mutator container-------------------

const paramCreateJoinContainerJson = {
  'type': 'param_create_join_container',
  'message0': '参数 %1 %2',
  'args0': [{
    'type': 'input_dummy'
  },
  {
    'type': 'input_statement',
    'name': 'STACK'
  }],
  'style': 'text_blocks',
  'tooltip': '设置参数',
  'enableContextMenu': false
}
Blockly.Blocks['param_create_join_container'] = {
  init: function () {
    this.jsonInit(paramCreateJoinContainerJson)
  }
}

// 3------------参数的mutator 参数项----------------
const paramCreateJoinItemJson = {
  'type': 'param_create_join_item',
  'message0': '参数',
  'previousStatement': null,
  'nextStatement': null,
  'style': 'text_blocks',
  'tooltip': '',
  'enableContextMenu': false
}
Blockly.Blocks['param_create_join_item'] = {
  init: function () {
    this.jsonInit(paramCreateJoinItemJson)
  }
}
